# -*- coding: utf8 -*-
#
# Copyright (c) 2009 Matías Ribecky <status-notifications@mribecky.com.ar>
#
# This file is part of status-notifications.
# 
# status-notifications is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# status-notifications is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with status-notifications.  If not, see <http://www.gnu.org/licenses/>.

"""Locate data files."""

import os

import xdg.BaseDirectory

DATA_DIRECTORY = 'status-notifications'
PLUGIN_PATH = list(xdg.BaseDirectory.load_data_paths(
                                      os.path.join(DATA_DIRECTORY, 'plugins')))

class DataMissing(Exception):
    pass

def get(*components):
    """Get the full path of a data file."""
    data_paths = xdg.BaseDirectory.load_data_paths(DATA_DIRECTORY)
    for directory in data_paths:
        full_path = os.path.join(directory, *components)
        if os.path.exists(full_path):
            return full_path
    raise DataMissing("Could not find file '%s'" % os.path.join(*components))
